<!DOCTYPE html>
<html lang="zh-CN"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="https://v3.bootcss.com/favicon.ico">

    <title>计算一元三次方程</title>

    <!-- Bootstrap core CSS -->
    <link href="source/css/bootstrap.css" rel="stylesheet">


    <!-- Custom styles for this template -->
    <link href="source/css/jumbotron-narrow.css" rel="stylesheet">
	
	<script>
		function cac(){
			var a,b,c,d;
			var input_a = document.getElementById("a");
			var input_b = document.getElementById("b");
			var input_c = document.getElementById("c");
			var input_d = document.getElementById("d");
			a = input_a.value;
			b = input_b.value;
			c = input_c.value;
			d = input_d.value;
			
			var y11, y12, y21, y22, y31, y32, p, q, r, u, v, g, h, fai;
			
		p = (3*a*c-b*b)/(3*a*a);
        q = (2 * b *b*b - 9 * a * b * c + 27 * a*a * d) / (27 * a *a*a);
        r = b / (3 * a);
        h = (q/2)*(q/2) + (p/3)*(p/3)*(p/3);
        g = Math.sqrt(h);
        
        
        
        if(h >= 0.000001){
            if((-q / 2) + g < 0){
                u = -Math.pow((Math.abs((-q / 2) + g)) ,1/3);

            }else{
                u = Math.pow((Math.abs((-q/2) + g)) ,1/3);
            }


            if((-q / 2) - g < 0){
                v = -Math.pow((Math.abs((-q / 2)-g)) ,1/3);

            }else{
            	v = -Math.pow(((-q / 2)-g) ,1/3);
            }
           

            if(h = 0){
                y11 = u + v - r;
                y12 = 0;
                y21 = -(u + v) / 2 - r;
                y22 = 0;
                y31 = -(u + v) / 2 - r;
                y32 = 0;
            }else{
                y11 = u + v - r;
                y12 = 0;
                y21 = -(u + v) / 2 - r;
                y22 = Math.sqrt(3)* (u - v) * 0.5;
                y31 = -(u + v) / 2 - r;
                y32 = -Math.sqrt(3)* (u - v) * 0.5;
			}

        	}else{
            fai = Math.acos((-q / 2) / Math.sqrt(Math.abs(p *p*p) / 27));
            y11 = 2 * Math.sqrt(Math.abs(p)/ 3) * Math.cos(fai / 3) - r;
            y21 = -2 * Math.sqrt(Math.abs(p) / 3) * Math.cos((fai + Math.PI) / 3) - r;
            y31 = -2 * Math.sqrt(Math.abs(p) / 3) *Math.cos((fai - Math.PI) / 3) - r;
            y12 = 0
            y22 = 0
            y32 = 0
			}
		
			var input_x11 = document.getElementById("x11");
			var input_x12 = document.getElementById("x12");
			var input_x21 = document.getElementById("x21");
			var input_x22 = document.getElementById("x22");
			var input_x31 = document.getElementById("x31");
			var input_x32 = document.getElementById("x32");
			input_x11.value = y11;
			input_x12.value = y12;
			input_x21.value = y21;
			input_x22.value = y22;
			input_x31.value = y31;
			input_x32.value = y32;
		
		
			
		}
	</script>

  </head>

  <body>

    <div class="container">
      <div class="header clearfix">
        <nav>
          <ul class="nav nav-pills pull-right">
            <li role="presentation" class="active"><a href="#">首  页</a></li>
            <li role="presentation" ><a href="#">关于我们</a></li>
          </ul>
        </nav>
        <h3 class="text-muted">计算一元三次方程根</h3>
      </div>

      <div class="jumbotron" style="margin-bottom: 0px;">
        <h1><i>a</i>x<sup>3</sup>+<i>b</i>x<sup>2</sup>+<i>c</i>x+<i>d</i>=0</h1>
        <p class="lead">
		a=<input type="text" id="a"  style="width: 80px;" />
		b=<input type="text" id="b"  style="width: 80px;" />
		c=<input type="text" id="c"  style="width: 80px;" />
		d=<input type="text" id="d"  style="width: 80px;" />
        
        </p>
        <p><a class="btn btn-lg btn-success" href="#" role="button" style="width: 200px;"onclick="cac()" >
        	计&nbsp;&nbsp;&nbsp;&nbsp;  算</a></p>
      </div>

      <div class="row marketing" style="text-align: center; margin-top: 0px;" >
          <h3>x<sub>1</sub>=
          	<input type="text"style="width: 150px;" id="x11"/> + 
          	<input type="text"style="width: 150px;" id="x12"/>
          	<i>i</i></h3>
          	
          <h3>x<sub>2</sub>=
          	<input type="text"style="width: 150px;" id="x21"/> + 
          	<input type="text"style="width: 150px;" id="x22"/>
          	<i>i</i></h3>
          
          <h3>x<sub>3</sub>=
          	<input type="text"style="width: 150px;" id="x31"/> + 
          	<input type="text"style="width: 150px;" id="x32"/>
          	<i>i</i></h3>
      </div>

      <footer class="footer">
        <p>© 2016 Company, Inc.</p>
      </footer>

    </div> <!-- /container -->


    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="Narrow%20Jumbotron%20Template%20for%20Bootstrap_files/ie10-viewport-bug-workaround.js"></script>
  

</body></html>